package com.powernode.ssm.serviceImpl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.io.FileUtil; 
import cn.hutool.core.util.ArrayUtil;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.powernode.ssm.dao.*;
import com.powernode.ssm.pojo.vo.*;
import com.powernode.ssm.pojo.po.*;
import com.powernode.ssm.pojo.bo.*;
import com.powernode.ssm.service.*;
import com.powernode.ssm.utils.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

@Slf4j
@Service
public class LogInfoServiceImpl extends ServiceImpl<LogInfoDao, LogInfoPo> implements LogInfoService {

   @Autowired
   LogInfoDao logInfoDao;

   @Value("${export.template_path}")
   private String tempPath;
   @Value("${export.exportPath}")
   private String exportPath; 

   @Value("${export.dsp}")
   private boolean encrypt;

   @Override
   public ResponseUtils queryLogInfo (QueryLogInfoVo queryLogInfoVo) {

       int current = queryLogInfoVo.getCurrentPage();
       int size = queryLogInfoVo.getPageSize();

        Page<LogInfoPo> page = logInfoDao.queryLogInfo(
               new Page<>(current, size), queryLogInfoVo);

        PageBo pageBo = PageBo.builder()
               .current(current)
               .size(size)
               .total(page.getTotal())
               .dataList(page.getRecords())
               .build();

       return new ResponseUtils<>(ReturnCodeEnum.SUCCESS.getCode(),ReturnCodeEnum.SUCCESS.getMsg(),pageBo);
   }

   @Override
   public ResponseUtils saveLogInfo (SaveLogInfoVo saveLogInfoVo) {

       String id = saveLogInfoVo.getId();
       int num = logInfoDao.countLogInfo(id);
       if (num>0){
           return new ResponseUtils<>(ReturnCodeEnum.SAME_RECORD_ERR.getCode(), ReturnCodeEnum.SAME_RECORD_ERR.getMsg(), null);
       }
       logInfoDao.insertLogInfo(saveLogInfoVo);

       return new ResponseUtils<>(ReturnCodeEnum.SUCCESS.getCode(), ReturnCodeEnum.SUCCESS.getMsg(), null);
   }

}
